package com.feng.annotation.service;

import com.feng.annotation.bean.User;
import com.feng.annotation.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;
import java.util.UUID;

/**
 * @author Lee
 * @date 2019/3/9
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    @Transactional
    public void saveUser(){
        Random random = new Random();
        User user = new User();
        user.setUsername(UUID.randomUUID().toString().substring(20));
        user.setAge(random.nextInt(100));

        try {
            userDao.insertUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int i = 10/0;
    }

}
